import Vue from 'vue'
import {
    HomeNewGame,
    HomeGameNews,
    HomeBanner,
    HomeCredit,
    HomeActivity,
    GameList,
    ListData,
    GameDetails,
    GiftGame
} from '@/api'
export default {
    //   取首页新游速递、游戏资讯、轮播图、精彩活动等数据
    fetchHomeData({ commit }, parameter) {
        const game = { doAjax: 'game', cache: true }
        return HomeNewGame(game).then(data => {
            if (data) commit('setHomeNewGame', data)
            const banner = { doAjax: 'banner', cache: true }
            return HomeBanner(banner).then(data => {
                if (data) commit('setHomeBanner', data)
                const activity = { doAjax: 'activity', cache: true }
                return HomeActivity(activity).then(data => {
                    if (data) commit('setHomeActivity', data)
                    const news = { doAjax: 'news', cache: true }
              

                })
            })
        })

    },

    //   fetchHomeData({ commit }, parameter) {
    //     const game = {doAjax: 'game', cache: true}
    //     return HomeNewGame(game).then(data => {
    //       if (data) commit('setHomeNewGame', data)
    //         const news = {doAjax: 'news', cache: true}
    //       return HomeGameNews(news).then(data => {
    //         if (data) commit('setHomeGameNews', data)
    //           const banner = {doAjax: 'banner', cache: true}
    //         return HomeBanner(banner).then(data => {
    //           if (data) commit('setHomeBanner', data)
    //             const activity = {doAjax: 'activity', cache: true}
    //           return HomeActivity(activity).then(data => {
    //             if (data) commit('setHomeActivity', data)
    //           })
    //         })
    //       })
    //     })
    //   },


    // 取游戏页面游戏列表等数据
    fetchGameList({ commit }, parameter) {
        // return GameList(parameter).then(data => {
        //     if (data) commit('setGameList', data)
        // })
    },
    // 取榜单页面数据
    fetchListData({ commit }, parameter) {
        // return ListData(parameter).then(data => {
        //     if (data) {
        //         data.page = parameter.page
        //         commit('setListData', data)
        //     }
        // })
    },
    // 取游戏详情数据
    fetchGameDetails({ commit }, parameter) {
        return GameDetails(parameter).then(data => {
            if (data) {
                data.gameId = parameter.gameId
                commit('setGameDetails', data)
            }
            const n = parseInt(Math.random() * 9 + 1)
            const obj = { device: '', type: '', label: '', page: n, cache: true }
            return GameList(obj).then(data => {
                if (data) commit('setBottomGame', data)
            })
        })
    },
    // 取游戏礼包数据
    fetchGiftGame({ commit }, parameter) {
    
    }
}